﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LL.Business;
using NanoERP.Model;

namespace NanoERP.Business.BaseInfo
{
    /// <summary>
    /// 数据字典业务类
    /// </summary>
    public class SysdictableBLL : ServiceBase
    {
        /// <summary>
        /// 数据字典查询
        /// </summary>
        /// <param name="parentid">上级节点Id</param>
        /// <returns></returns>
        public List<Sysdictable> Query(int parentid)
        {
            var session = this.DbSession;

            return session.Query<Sysdictable>("PARENT=@0 AND STATE=@1", parentid, 0).ToList();
        }

        /// <summary>
        /// 获取指定字典值
        /// </summary>
        /// <param name="id">字典ID</param>
        /// <returns></returns>
        public Sysdictable Get(int id)
        {
            var session = this.DbSession;
            return session.Get<Sysdictable>(id);
        }

        /// <summary>
        /// 编辑数据字典
        /// </summary>
        /// <param name="o">字典对象</param>
        public void Edit(Sysdictable o)
        {
            if (o.Id == 0) this.DbSession.Insert(o, "Id");
            else
                this.DbSession.Update(o);
        }

        /// <summary>
        /// 删除数据字典
        /// </summary>
        /// <param name="id"></param>
        public void Delete(Sysdictable o)
        {
            var session = this.DbSession;
            o.State = -1;
            session.Update(o);
        }
    }
}
